/*处方点评列表查询js
 * 2018-02
 */
var prescriptionList = (function(){
	var pageSize = 10,currPage = 1;
	layer.msg('查询中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500});
	var getParam = function(tname){
		var selectedId = $("#"+tname).jqGrid("getGridParam", "selrow");
    	var rowData = $("#"+tname).jqGrid("getRowData", selectedId);
    	return rowData;
	}
	/************************************接口****************************************/
	 /**
     *1 处方列表查询接口
     * basequeryPage分页调用这个，currPage，pageSize
     */
    var initPrescriptList = function(){
    	debugger;
        var def = $.Deferred();
        var bdate = "'"+$("#sdate").val()+"'";
        var edate = "'"+$("#edate").val()+"'";
        var param = {params:JSON.stringify({sqlId:16500,bdate:bdate,edate:edate,currPage:currPage,pageSize:pageSize})};
        $.ajax({
        	type: "GET",
        	url: hostUrl+"/basicinformationquery/basequeryPage",
        	data:param,
        	dataType: "json",
        	success: function (resp) {
        		def.resolve(resp);
        	}
        });
        return def.promise();
    }
    /**
     *2  处方点评明细信息接口
     */
    var detailPrescriptionInfo = function(rowData){
    	rowData.acf01 = rowData.apart;
    	rowData.bck01 = rowData.bck01c;
    	rowData.qab06 = rowData.cbm16;
    	var cbm01 = rowData.cbm01;
    	var def = $.Deferred();
    	var param = {params:JSON.stringify({sqlId:16507,apart:1,cbm01:cbm01})};
    	$.ajax({
    		type: "get",
    		url: hostUrl+"/basicinformationquery/basequery",
    		data:param,
    		dataType: "json",
    		success: function (resp) {
    			var list = [];
    			for(var i=0;i<resp.list.length;i++){
    				var temp = $.extend(resp.list[i],rowData);
    				temp.qab14 = 1;
    				list.push(temp);
    			}
    			def.resolve(list);
    		}
    	});
    	return def.promise();
    }
    /**
     * 3 处方点评保存接口
     */
    var savePrescription = function(list){
    	 var def = $.Deferred();
    	 var params= {
    			 bce01:1,
    			 bce03:"管理员",
    			 qaa01:list[0].qaa01,
    			 qab1:list
    	 }
         var param = {procId:"quality_qaa1_edit",
        		      params:JSON.stringify(params)
        		 };
         $.ajax({
         	type: "POST",
         	url: hostUrl+"/basicinformationquery/updateProc",
         	data:param,
         	dataType: "json",
         	success: function (resp) {
         		def.resolve(resp);
         	}
         });
         return def.promise();
    }
   
    /**
     * 4 处方明细接口
     */
    var PrescriptionDetail = function(){
    	var info = getParam("prescript_item");
    	var def = $.Deferred();
    	var param = {params:JSON.stringify({sqlId:16504,cbm01:info.cbm01})};
    	$.ajax({
    		type: "get",
    		url: hostUrl+"/basicinformationquery/basequery",
    		data:param,
    		dataType: "json",
    		success: function (resp) {
    			def.resolve(resp.list);
    		}
    	});
    	return def.promise();
    }
    /**
     * 5 处方诊断接口
     */
    var prescriptionDiagnose = function(){
    	var info = getParam("prescript_item");
    	var def = $.Deferred();
    	var param = {params:JSON.stringify({sqlId:16505,cbm01:info.cbm01})};
    	$.ajax({
    		type: "get",
    		url: hostUrl+"/basicinformationquery/basequery",
    		data:param,
    		dataType: "json",
    		success: function (resp) {
    			def.resolve(resp.list);
    		}
    	});
    	return def.promise();
    }
    /**
     * 6 查询处方保存参数接口
     */
    var getPrescriptionId = function(count){
    	var def = $.Deferred();
    	var param = {params:JSON.stringify({count:count})};//rows+1
    	$.ajax({
    		type: "get",
    		url: hostUrl+"/basicinformationquery/queryNewId",
    		data:param,
    		dataType: "json",
    		success: function (resp) {
    			def.resolve(resp.list);
    		}
    	});
    	return def.promise();
    }
    /************************************接口****************************************/
    /**
     * 显示处方列表
     */
    var showPrescripList = function(){
    	 layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*600}); 
    	 var bdate = "'"+$("#sdate").val()+"'";
         var edate = "'"+$("#edate").val()+"'";
         var param = {params:JSON.stringify({sqlId:16500,bdate:bdate,edate:edate,currPage:currPage,pageSize:pageSize})};
    	 var tname = 'prescript_item';
    	 $('#prescript_item_container').resize(function(){
    		$("#"+tname).setGridWidth($("#prescript_item_container").width()*1);
    	 });
         jQuery('#'+tname).GridUnload();
         jQuery("#"+tname).jqGrid({
        	url : hostUrl+"/basicinformationquery/basequeryPage",
        	postData : param,
        	mtype : 'get',
        	datatype : "json",
            colModel :
                [
                    {label: '处方编号',name: 'cbm01',  align: 'center', width: '90'},
                    {label: '处方日期',name: 'cbm16',  align: 'center', width: '130'},
                    {label: '病人姓名',name: 'vaa05',  align: 'center', width: '80'},
                    {label: '性别',name: 'abw02',  align: 'center', width: '80'},
                    {label: '年龄',name: 'agep',  align: 'center', width: '80'},
                    {label: '开单科室',name: 'bck03c',  align: 'center', width: '80'},
                    {label: '处方医师',name: 'bce03',  align: 'center', width: '80'},
                    {label: '处方分类',name: 'cbm06',  align: 'center', width: '80'},
                    {label: '病人科室',name: 'bck03b',  align: 'center', width: '80'},
                    {label: '操作',name: 'mange',  align: 'center',
	                	 cellattr: function(rowId, tv, rawObject, cm, rdata) {
	                         return 'id='+tname+'_mange' + rowId;
	                	 }
                    },
                    {label: 'apart',name: 'apart',hidden:true},
                    {label: 'vaa01',name: 'vaa01',hidden:true},
                    {label: 'bce01',name: 'bce01',hidden:true},
                    {label: 'bce03',name: 'bce03',hidden:true},
                    {label: 'bck01c',name: 'bck01c',hidden:true},
                    {label: 'vaa07',name: 'vaa07',hidden:true},
                ],
            rowNum :pageSize ,
            height : 'auto',
            width : "auto",
            autowidth : true,
        	forceFit:true,
            shrinkToFit:true,
        	rownumbers : true,
        	jsonReader: {
				page: "page",
				total: "total",
				records: "records",
				repeatitems: false,
				rows: "rows"

			},
            onSelectRow : function(id,status){
            	showPrescripItem(); //处方明细
            	showPrescripDiagnose();//处方诊断
            	PrescripDetailTable();
            },
            loadComplete : function(data)
            {
            	debugger;
            	var ids = jQuery("#"+tname).jqGrid('getDataIDs');
    			for (var i = 0; i < ids.length; i++)
    			{
    				var cl = ids[i];
    				var copyInput = "<button class='btn btn-min btn-resver' onclick='prescriptionList.addToprescript("+cl+")' >加入处方点评</button>";
    				copyInput += "<button class='btn btn-min btn-resver' onclick='prescriptionList.viewMedicalInfo("+cl+")' >医疗信息预览</button>";
    				jQuery("#"+tname).jqGrid('setRowData', ids[i],
    						{
    							mange : copyInput
    						});
    			}
    			loadPage(currPage);
            },
        })
    };
    //分页
    var loadPage = function(curr){
    	
    	var tname = 'prescript_item';
		var totalRecord = $("#"+tname).jqGrid('getGridParam', 'records');
		$('#'+tname+'_total').text(totalRecord);
		if (totalRecord <= 0) {
			var $tr = $('#'+tname).find('tbody>tr:last');
			if($tr.length){
				var len = $tr.find('td').length;
				len = parseInt(len);
				$tr.after($('<tr><td colspan="'+len+'" style="text-align:left;">没有符合条件的数据！</td></tr>'));
			}
			return;
		}
		var rowscount = pageSize;
		var totalPage = 1;
		var totalyu = parseInt(totalRecord) % parseInt(rowscount);
		if (totalyu == 0) {
			totalPage = parseInt(totalRecord) / parseInt(rowscount);
		}
		else {
			totalPage = parseInt(totalRecord - totalyu) / parseInt(rowscount) + 1
		}

		laypage(
			{
				cont: 'prescript_page', // 容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
				pages: totalPage, // 通过后台拿到的总页数
				curr: curr || 1, // 当前页
				skip: true, // 是否开启跳页
				jump: function (obj, first) { // 触发分页后的回调
					if (!first) { // 点击跳页触发函数自身，并传递当前页：obj.curr
						currPage = obj.curr;
						layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*600});
						loadPage(currPage);

					}
				}
			});
		reloadGrid(curr);

	}
	var reloadGrid = function(pageNumber){
		var bdate = "'"+$("#sdate").val()+"'";
	    var edate = "'"+$("#edate").val()+"'";
		if(pageNumber==undefined||pageNumber==''){
			pageNumber = 1;
		}
		var param = {params:JSON.stringify({sqlId:16500,bdate:bdate,edate:edate,currPage:pageNumber,pageSize:pageSize})};
		jQuery("#prescript_item").jqGrid('setGridParam',
			{
				url: hostUrl+"/basicinformationquery/basequeryPage",
				postData: param,
				datatype: "json",
				mtype: "GET"
			}).trigger('reloadGrid');// 重新载入
	    }
    //加入处方点评
    var addToprescript = function(rowId){
    	debugger;
    	event.stopPropagation();
    	layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500});
    	var tname = 'prescript_item';
    	var rowData = $("#"+tname).jqGrid("getRowData",rowId);
    	$.when(
    		 detailPrescriptionInfo(rowData)
	        ).done(function (data) {
	        	debugger;
	        	if($("#dianping_item_table").find("tbody").length>0){ //判断有没有表格
	        		addPrescripRow(data[0]);
	        	}else{
	        		PrescripDetailTable(data);
	        	}
	    });
    }
    //处方点评表格可编辑
    var item_edit_row,item_edit_col,lastcellName;
    var PrescripDetailTable = function(arr){
    	var tname = 'dianping_item_table';
    	$('#dianping_item_container').resize(function(){
    		$("#"+tname).setGridWidth($("#dianping_item_container").width()*1);
    	});
        jQuery('#'+tname).GridUnload();
        jQuery("#"+tname).jqGrid({
            datatype: 'local',
            data:arr,
            colModel :
                [
                    {label: '处方日期',name: 'cbm16',  align: 'center', width: '130'},
                    {label: '处方号',name: 'cbm01',  align: 'center', width: '115'},
                    {label: '病人姓名',name: 'vaa05',  align: 'center', width: '55'},
                    {label: '性别',name: 'abw02',  align: 'center', width: '30'},
                    {label: '年龄（岁）',name: 'agep',  align: 'center', width: '40'},
                    {label: '处方诊断',name: 'qab10',  align: 'center', editable : true,editoptions: {class: 'form-input'},width: '130'},
                    {label: '药品品种',name: 'qab11',  align: 'center', editable : true,editoptions: {class: 'form-input'},width: '30'},
                    {label: '抗菌处方用药',name: 'qab15',  align: 'center', editable : true,editoptions: {class: 'form-input'},width: '40'},
                    {label: '注射剂处方',name: 'qab14',  align: 'center',editable : true,edittype : 'checkbox',formatter : 'checkbox', width: '60',
                    	editoptions :
    					{
    						value : "1:0",
    						defaultValue: 0
    					}
                    },
                    {label: '国家基本药物品种数',name: 'qab13',  align: 'center',editable : true,editoptions: {class: 'form-input'}, width: '40'},
                    {label: '药品通用名数',name: 'qab12',  align: 'center',editable : true,editoptions: {class: 'form-input'}, 	 width: '40'},
                    {label: '处方金额',name: 'qab16',  align: 'center', width: '60'},
                    {label: '处方医师',name: 'bce03a',  align: 'center', width: '60'},
                    {label: '审核调配药师',name: 'bce03b',  align: 'center', width: '40'},
                    {label: '核对发药药师',name: 'bce03c',  align: 'center', width: '40'},
                    {label: '是否合理',name: 'qab22',  align: 'center',editable : true,edittype : 'checkbox',formatter : 'checkbox', width: '30',
                    	editoptions :
    					{
    						value : "1:0",
    						defaultValue: 0
    					}
                    },
                    {label: '存在问题因素',name: 'promItem',  align: 'center',editable: true, editoptions: {class: 'form-input'}, width: '150'},
                	{label: '存在问题编码',name: 'blk02',  align: 'center', width: '40'},
                    {label: '备注',name: 'bck03b',  align: 'center',editable : true,editoptions: {class: 'form-input'}, width: '50'},
                    {label: 'qab01',name: 'qab01',  hidden: true},
                    {label: 'qaa01',name: 'qaa01',  hidden: true},
                    {label: 'vaa01',name: 'vaa01',  hidden: true},
                    {label: 'bce01',name: 'bce01',  hidden: true},
                    {label: 'recordid',name: 'recordid',  hidden: true},
                    {label: 'acf01',name: 'acf01',  hidden: true},
                    {label: 'bck01',name: 'bck01',  hidden: true},
                    {label: 'bce03',name: 'bce03',  hidden: true},
                    {label: 'vaa07',name: 'vaa07',hidden:true},
                    {label: 'qab06',name: 'qab06',hidden:true},
                ],
            height : 'auto',
            width : "auto",
            autowidth : true,
        	forceFit:true,
            shrinkToFit:true,
            cellEdit : true,
			cellsubmit : "clientArray", // 表示在本地进行修改
			onCellSelect: function (rowid, iCol, cellcontent, e) {
				debugger;
                if (!!item_edit_row && lastcellName == 'promItem') {
                	destroyDropdown("dianping_item_table");
                }
            },
			beforeEditCell : function(rowid, cellname, value, iRow, iCol)
			{
				lastcellName = cellname
				item_edit_row = iRow;
				item_edit_col = iCol;
			},
			afterEditCell: function (rowid, cellname, v, iRow, iCol) {
                //收费项目添加下拉treebox
				debugger;
                if (cellname == 'promItem') {
                	var param = {sqlId:16506};
                    $('#' + rowid + '_' + cellname).dropdownGrid({
                        jqgridOp:{
                            url : hostUrl+"/basicinformationquery/basequery",
                            postData : param,
                            width : '700',
                            colModel : [
                                {name : 'blk02', label:'编码', width:'30'},
                                {name : 'blk04', label:'不确定疾病名称', width:'250'},
                                {name : 'blk03', label:'分类', width:'80'},
                            ],
                            jsonReader: {
                                page: "page",
                                total: "total",
                                records: "records",
                                repeatitems: false,
                                root: "list"
                            },
                            
                        },
                        dropDownOp:{
                            width: '704px',
                            height:'600px',
                            pagination: {
                                allowPagination : false,
                            }
                        },
                        viewCol:'blk04', //放的字段
                        searchField:'txt',  //搜索
                        
                    });
                    $('#' + rowid + '_' + cellname+ '_dropdownGrid').on('selectedRow.dropdownGrid', function (e, relatedObj) {
                        var rowData = relatedObj.selectedData;
                        var $target = relatedObj.relatedTarget;
                        var $code = $target.parents('tr').find('td[aria-describedby="dianping_item_table_blk02"]');
                        $code.text(rowData.blk02);
                        $code.data('selectedData', rowData);
                    });
                }
            },
            
            loadComplete : function(data)
            {
            },
        })
    }
    var destroyDropdown = function(tableid,isave){
    	 var ids = $("#"+tableid).jqGrid('getDataIDs');
		 for(var i=0;i<ids.length;i++){
			  var $mediadv = $('#'+tableid).find("#"+ids[i]).find('td[aria-describedby="dianping_item_table_promItem"]').find("input");
			  $mediadv.dropdownGrid('destroy');
		 }
		 if(isave){
			 jQuery('#'+tableid).jqGrid("saveCell", item_edit_row,item_edit_col);
			 jQuery('#'+tableid).jqGrid("restoreCell",item_edit_row,item_edit_col);
		 }
    }
    //添加处方点评，可增加多条数据
    var addPrescripRow = function(rowData)
    {
    	debugger;
    	var isExist =isExistInPrescrip(rowData);
    	if(isExist){
    		layer.msg('此处方已经加入点评！', {
				time : 4000,
				icon : 0,
				skin: 'layui-layer-msg0'
			});
    		return false;
    	}
    	    var tableid= "dianping_item_table"
	   	    destroyDropdown(tableid,true);
        	var dataRow =
        	{
        	'cbm16' :   rowData.cbm16,
        	'cbm01' :   rowData.cbm01,
        	'vaa05' :   rowData.vaa05,
        	'abw02' :   rowData.abw02,
        	'agep'  :   rowData.agep,
        	'qab10' :   rowData.qab10,
        	'qab11' :   rowData.qab11,
        	'vcf11' :   rowData.vcf11,
        	'qab15' :   rowData.qab15,
        	'qab14' :   rowData.qab14,
        	'qab13' :   rowData.qab13,
        	'qab12' :   rowData.qab12,
        	'qab16' :   rowData.qab16,
        	'bce03a' :  rowData.bce03a,
        	'bce03b' :  rowData.bce03b,
        	'bce03c' :  rowData.bce03c,
        	'qab22' :   rowData.qab22,
        	'promItem': rowData.promItem,
        	'qab24' :   rowData.qab24,  //备注
        	'qab01' :   rowData.qab01,
        	'qaa01' :   rowData.qaa01,
        	'vaa01' :   rowData.vaa01,
        	'bce01' :   rowData.bce01,
        	'recordid': rowData.recordid,
        	'acf01' :   rowData.acf01,
        	'bck01' :   rowData.bck01,
        	'bce03' :   rowData.bce03,
        	'vaa07' :   rowData.vaa07,
        	'qab06' :   rowData.qab06,
        	};
        	// 将新添加的行插入到第一列
        	var ids = $("#"+tableid).jqGrid('getDataIDs');
        	$("#"+tableid).jqGrid("addRowData", (ids.length + 1), dataRow, "last");
    }
    //判断加入点评的处方是否已经存在
    var isExistInPrescrip = function(rowData){
    	var isExist = false;
    	var tableid= "dianping_item_table"
        var ids = $("#"+tableid).jqGrid('getDataIDs');
    	for(var i=0;i<ids.length;i++){
    		var row = $("#"+tableid).jqGrid("getRowData",ids[i]);
    		if(row.cbm01 == rowData.cbm01){
    			isExist = true;
    		}
    	}
    	return isExist;
    }
    //删除处方点评，前台处理
    var deletePrescripInfo = function(){
    	var tname = "dianping_item_table";
    	var selectedId = $("#"+tname).jqGrid("getGridParam", "selrow");
    	$("#" + tname).jqGrid("delRowData", selectedId);
    }
    //保存处方点评
    var savePrescripInfo = function(){
    	debugger;
    	layer.msg('保存中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500});
    	var tname = 'dianping_item_table';
    	jQuery('#'+tname).jqGrid("saveCell", item_edit_row,item_edit_col);
		jQuery('#'+tname).jqGrid("restoreCell",item_edit_row,item_edit_col);
    	var ids = $("#"+tname).jqGrid('getDataIDs');
    	var curve = $('#'+tname).jqGrid('getRowData');
    	if(curve.length<1){
    		layer.msg('没有要保存的数据，请检查！', {
				time : 4000,
				icon : 0,
				skin: 'layui-layer-msg0'
			});
    		return false;
    	}
    	$.when(
    		getPrescriptionId(ids.length+1)
        ).done(function (data) {
        	for(var i=0;i<curve.length;i++){
        		curve[i]["qab01"] = data[i];
        		curve[i]["qaa01"] = data[curve.length];
        	}
        	$.when(
        			savePrescription(curve)
    	        ).done(function (data) {
    	        	if(data.result == 'Success'){
    	        		layer.msg('保存成功！', {
    	    				time : 2000,
    	    				icon : 1,
    	    				skin: 'layui-layer-msg1'
    	    			});
    	        		//刷新列表
    	        		showPrescripList();
    	        		PrescripDetailTable();
    	        	}
    	    });
        })
    	
    }
    //医疗信息预览
    var viewMedicalInfo = function(rowId){
    	debugger;
    	var tname = 'prescript_item';
    	var rowData = $("#"+tname).jqGrid("getRowData",rowId);
    	var apart = rowData.apart;
    	var vaa07 = rowData.vaa07;
    	var url;
    	if(apart == 1){  //门诊
    		
    		url = osworksUrl+'/opertaint_menzhen.jsp?vaa07='+vaa07+"&jsessionids="+jsessionids;
    	}else if(acf01 == 2){ //住院
    	    url = osworksUrl+'/osworksweb/operating_hocussFirst.jsp?vae01='+vaa07+"&jsessionids="+jsessionids;
    	}
    	var index = layer.open({
			type : 2,
			title : "医疗信息预览",
			area : [ "95%", "95%" ],
			shade : 0.1,
			maxmin : true,
			content : url,
			closeBtn : 1,
			cancel: function(index){ 
			},
		    success:function(layero){
    		  iframeName = $(layero).find("iframe").attr("name");
	        },
	       	min: function (layero) {
	            var times = layero.attr('times');
	            $('#layui-layer-shade' + times).hide();
	        },
	        restore: function (layero) {
	            var times = layero.attr('times');
	            if ($('#layui-layer-shade' + times).css('display') == 'none') {
	                $('#layui-layer-shade' + times).show();
	            }
	        },
		})
    }
    //处方明细展示
    var showPrescripItem = function(){
    	layer.msg('查询中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500});
    	$.when(
    			PrescriptionDetail()
	        ).done(function (data) {
	        	showDetailTable(data)
	    });
    }
    //处方明细展示 -- 表格
    var showDetailTable = function(arr){
    	var tname = 'prescript_detail';
    	$('#prescript_detail_container').resize(function(){
    		$("#"+tname).setGridWidth($("#prescript_detail_container").width()*1);
    	});
        jQuery('#'+tname).GridUnload();
        jQuery("#"+tname).jqGrid({
            datatype: 'local',
            data:arr,
            colModel :
                [
                    {label: '组',name: 'cbm01', width: '100'},
                    {label: '序号',name: 'rownr', width: '30'},
                    {label: '医嘱内容',name: 'vaf22', width: '200'},
                    {label: '剂量',name: 'vaf20', width: '40'},
                    {label: '单位',name: 'bdg02', width: '40'},
                    {label: '总量',name: 'vaf21', width: '40'},
                    {label: '单位',name: 'funit', width: '40'},
                    {label: '频次',name: 'vaf26', width: '60'},
                    {label: '嘱托',name: 'vaf23', width: '80'},
                    {label: '执行时间方案',name: 'vaf30', width: '80'},
                    {label: '执行性质',name: 'vaf58',width: '80',
                	 formatter:function(cellvalue, options, rowObject){
                         switch (cellvalue)
                         {
                           case 0 :
                              return "正常";
                              break;
                           case 1 :
                           	  return "自备药";
                           	  break;
                           case 2 :
                              return "离院带药";
                              break;
                           case 3 :
                           	  return "医技单独生成条码 ";
                           	  break;
                           case 4 :
                    	      return "院外执行 ";
                    	      break;
                           case 5 :
                        	  return "外配处方 ";
                        	  break;
                           default :
                              return "";
                              break;
                         }
                	 }
                    },
                    {label: '执行科室	',name: 'bck03b', width: '80'},
                    {label: '滴速',name: 'vaf60', width: '60'},
                    {label: '备注',name: 'vaf55', width: '80'},
                ],
            rowNum : arr.length,
            height : 'auto',
            width : "auto",
            autowidth : true,
        	forceFit:true,
            shrinkToFit:true,
        	rownumbers : true,
            beforeSelectRow : function(rowid, e){

            },
            onSelectRow : function(id,status){
            },
            loadComplete : function(data)
            {
            	noDataRemaind(data,tname);
            },
        })
    }
    //处方诊断
    var showPrescripDiagnose = function(){
    	layer.msg('查询中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500});
    	$.when(
    			prescriptionDiagnose()
	        ).done(function (data) {
	        	showDiagnoseTable(data)
	    });
    }
    var showDiagnoseTable = function(arr){
    	var tname = 'prescript_diagnose';
    	$('#prescript_diagnose_container').resize(function(){
    		$("#"+tname).setGridWidth($("#prescript_diagnose_container").width()*1);
    	});
        jQuery('#'+tname).GridUnload();
        jQuery("#"+tname).jqGrid({
            datatype: 'local',
            data:arr,
            colModel :
                [
                    {label: '诊断名称',name: 'vao15',  align: 'center'},
                ],
            rowNum : arr.length,
            height : 'auto',
            width : "auto",
            autowidth : true,
        	forceFit:true,
            shrinkToFit:true,
        	rownumbers : true,
            beforeSelectRow : function(rowid, e){

            },
            onSelectRow : function(id,status){
            },
            loadComplete : function(data)
            {
            	noDataRemaind(data,tname);
            },
        })
    }
    var noDataRemaind = function(data,tname){
    	if(data.records == 0){
			var $tr = $('#'+tname).find('tbody>tr:last');
			var len = $tr.find('td').length;
			$("#"+tname).html('<tr><td colspan="'+ parseInt(len)+ '" style="text-align:left;">没有符合条件的数据！</td></tr>');
		}
    }
    var initTime = function(){
    	var dd = new Date().Format("yyyy-MM-dd");
    	$("#sdate").val(dd);
        $("#edate").val(dd);
    }
    /**
     * 初始化信息
     */
    var initInfo = function(){
        initTime();    //初始化时间
        showPrescripList();
    }
    return {
        initInfo:initInfo,
        showPrescripList:showPrescripList,
        addToprescript:addToprescript,
        viewMedicalInfo:viewMedicalInfo,
        savePrescripInfo:savePrescripInfo,
        deletePrescripInfo:deletePrescripInfo,
    }
}());
$(function(){
	prescriptionList.initInfo();
});